<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="../image/favicon.ico" type="image/ico"/>

    <title>贵美后台管理系统</title>

    <!-- Bootstrap -->
    <link href="../css/bootstrapcss/bootstrap.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="../css/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="../css/vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="../css/vendors/iCheck/skins/flat/green.css" rel="stylesheet">

    <link href="../css/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-buttons-bs/css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-fixedheader-bs/css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-responsive-bs/css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="../css/vendors/datatables.net-scroller-bs/css/scroller.bootstrap.min.css" rel="stylesheet">


    <!-- bootstrap-progressbar -->
    <link href="../css/vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">
    <!-- JQVMap -->
    <link href="../css/vendors/jqvmap/dist/jqvmap.min.css" rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link href="../css/vendors/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">

    <link href="../css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="../css/build/css/custom.min.css" rel="stylesheet">
    <%
        request.setCharacterEncoding("utf-8");
    %>
    <style>
        form div {
            margin-top: 10px;
            margin-left: 15px;
        }

        #searchBtn {
            margin-top: 10px;
        }

        #searchBtn button {
            margin-left: 20px;
        }
    </style>
</head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">

        <jsp:include page="left.jsp"/>

        <!-- top navigation -->
        <jsp:include page="top.jsp"/>
        <!-- /top navigation -->

        <!-- page content -->


        <div class="right_col" role="main">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>商品分类管理</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                       aria-expanded="false">
                                        <i class="fa fa-wrench"></i>
                                    </a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <div id="datatable-checkbox_wrapper"
                                 class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                <div class="row">
                                    <div class="col-sm-12 text-center" style="overflow: hidden">
                                        <form class="form-inline" action="../Category/page.do" method="post">
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon1">分类ID</span>
                                                <input type="text" class="form-control" name="ctgrId"
                                                       placeholder="请输入名称"
                                                       aria-describedby="sizing-addon1" style="width: 120px">
                                            </div>
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon3">大类型</span>
                                                <select class="form-control big" name="bigCtgr" id="big"
                                                        style="width: 100px; text-align: center"
                                                        onchange="changSCtgr(this)">
                                                    <option value="">--请选择--</option>
                                                </select>
                                            </div>
                                            <div class="input-group input-group-sm">
                                                <span class="input-group-addon" id="sizing-addon2">小类型</span>
                                                <select class="form-control small" name="ctgrName" id="small"
                                                        style="width: 100px; text-align: center">
                                                    <option value="">--请选择--</option>
                                                </select>
                                            </div>


                                            <div class="col-sm-12 text-center" id="searchBtn">
                                                <button type="submit" class="btn btn-primary btn-sm">查询</button>
                                                <button type="reset" class="btn btn-default btn-sm">重置</button>
                                            </div>
                                        </form>
                                        <%--<form class="form-horizontal">--%>
                                        <%--<div class="form-group">--%>
                                        <%--<label for="inputEmail3" class="col-sm-2 control-label">Email</label>--%>
                                        <%--<div class="col-sm-10">--%>
                                        <%--<input type="email" class="form-control" id="inputEmail3" placeholder="Email">--%>
                                        <%--</div>--%>
                                        <%--</div>--%>
                                        <%--</form>--%>
                                        <%--<div id="datatable-keytable_filter" class="dataTables_filter">--%>
                                        <%--<label>--%>
                                        <%--Search:<input type="search" class="form-control input-sm" placeholder="" aria-controls="datatable-keytable">--%>
                                        <%--</label>--%>
                                        <%--</div>--%>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="table-responsive" style="margin-top: 10px">
                                            <table class="table table-striped table-bordered text-center">
                                                <thead>
                                                <tr>
                                                    <th style="text-align: center">分类ID</th>
                                                    <th style="text-align: center">大分类名称</th>
                                                    <th style="text-align: center">小分类名称</th>

                                                    <th style="text-align: center">操作</th>
                                                </tr>
                                                </thead>


                                                <tbody>
                                                <c:set var="categoryList" value="${categoryList}"/>


                                                <c:forEach var="item" items="${categoryList}">

                                                    <tr id="${item.ctgrId}">
                                                        <td>${item.ctgrId}</td>
                                                        <td>${item.bigCtgr}</td>
                                                        <td>
                                                            <p data-placement="left" data-toggle="popover"
                                                               data-trigger="hover" data-content="该分类目前共有55件">
                                                                    ${item.ctgrName}
                                                            </p>
                                                        </td>

                                                        <td>
                                                            <button class="btn btn-primary btn-sm" data-toggle="modal"
                                                                    data-target="#myModal" name="${item.ctgrId}"
                                                                    id="edit">
                                                                <span class="glyphicon glyphicon-edit"></span>
                                                            </button>
                                                            <a href="" class="btn btn-danger btn-sm delete">
                                                                <span class="glyphicon glyphicon-trash"></span>
                                                            </a>

                                                        </td>
                                                    </tr>
                                                </c:forEach>

                                                <!-- 模态框（Modal） -->
                                                <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                                                     aria-labelledby="myModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <button type="button" class="close" data-dismiss="modal"
                                                                        aria-hidden="true">×
                                                                </button>
                                                                <h3 class="modal-title" id="myModalLabel">
                                                                    修改分类
                                                                </h3>
                                                            </div>
                                                            <div class="modal-body">
                                                                <form action="">
                                                                    <div class="input-group input-group-sm">
                                                                        <span class="input-group-addon"
                                                                              id="sizing-addon4">大类型</span>
                                                                        <select class="form-control big" id="bigCtgr"
                                                                                style="width: 100px; text-align: center"
                                                                                onchange="changSCtgr(this)">
                                                                            <option value="">--请选择--</option>
                                                                        </select>
                                                                    </div>
                                                                    <%--<div class="input-group input-group-sm">--%>
                                                                    <%--<span class="input-group-addon" id="sizing-addon5">小类型</span>--%>
                                                                    <%--<select class="form-control small" --%>
                                                                    <%--style="width: 100px; text-align: center">--%>
                                                                    <%--<option value="">--请选择--</option>--%>
                                                                    <%--</select>--%>
                                                                    <%--</div>--%>
                                                                    <div class="input-group input-group-sm">
                                                                        <label for="ctgrName">小类型
                                                                            <input type="text" id="ctgrName">
                                                                        </label>
                                                                    </div>

                                                                </form>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default"
                                                                        data-dismiss="modal">
                                                                    关闭
                                                                </button>
                                                                <%--提交修改按钮--%>
                                                                <button type="button" class="btn btn-primary inserted">
                                                                    提交更改
                                                                </button>
                                                            </div>
                                                        </div><!-- /.modal-content -->
                                                    </div><!-- /.modal-dialog -->
                                                </div><!-- /.modal -->


                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <c:set var="page" value="${sessionScope.CategoryPage}" scope="session"/>


                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="dataTables_info" id="datatable-keytable_info" role="status"
                                         aria-live="polite">Showing ${page.firstIndex} to ${page.lastIndex}
                                        of ${page.totalRow} entries
                                        - current page is No${page.pageNo}
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="dataTables_paginate paging_simple_numbers"
                                         id="datatable-keytable_paginate">
                                        <ul class="pagination">
                                            <li class="paginate_button previous
                                                    <c:if test="${page.first}">
                                                        disabled
                                                    </c:if>"
                                                id="datatable-keytable_previous">

                                                <a href="../Category/page.do?pageNo=${page.getPrevNo()}"
                                                   aria-controls="datatable-keytable"
                                                   data-dt-idx="0" tabindex="0">Previous</a>
                                            </li>
                                            <%--<li class="paginate_button"><a--%>
                                            <%--href="../Category/page.do?pageNo=${page.pageNo-2}"--%>
                                            <%--aria-controls="datatable-keytable"--%>
                                            <%--data-dt-idx="1" tabindex="0">--%>

                                            <%--${page.pageNo-2}--%>
                                            <%--</a>--%>
                                            <%--</li>--%>
                                            <%--<li class="paginate_button "><a--%>
                                            <%--href="../Category/page.do?pageNo=${page.pageNo-1}"--%>
                                            <%--aria-controls="datatable-keytable"--%>
                                            <%--data-dt-idx="2" tabindex="0">--%>

                                            <%--<c:if test="${ page.pageNo-1 lt 0 } ">--%>
                                            <%--0--%>
                                            <%--</c:if>--%>
                                            <%--<c:if test="${page.pageNo-1 gt 0 }">--%>
                                            <%--${page.pageNo-1}--%>
                                            <%--</c:if>--%>
                                            <%--</a></li>--%>
                                            <%--<li class="paginate_button active"><a--%>
                                            <%--href="../Category/page.do?pageNo=${page.pageNo}"--%>
                                            <%--aria-controls="datatable-keytable"--%>
                                            <%--data-dt-idx="3" tabindex="0">${page.pageNo}</a></li>--%>
                                            <%--<li class="paginate_button "><a--%>
                                            <%--href="../Category/page.do?pageNo=${page.pageNo+1}"--%>
                                            <%--aria-controls="datatable-keytable"--%>
                                            <%--data-dt-idx="4" tabindex="0">--%>
                                            <%--<c:if test="${page.pageNo+1 ge page.totalPage}">--%>
                                            <%--${page.totalPage}--%>
                                            <%--</c:if>--%>
                                            <%--<c:if test="${page.pageNo+1 lt page.totalPage}">--%>
                                            <%--${page.pageNo+1}--%>
                                            <%--</c:if>--%>
                                            <%--</a></li>--%>
                                            <%--<li class="paginate_button "><a--%>
                                            <%--href="../Category/page.do?pageNo=${page.pageNo+2}"--%>
                                            <%--aria-controls="datatable-keytable"--%>
                                            <%--data-dt-idx="5" tabindex="0">--%>
                                            <%--<c:if test="${page.pageNo+2 ge page.totalPage}">--%>
                                            <%--${page.totalPage}--%>
                                            <%--</c:if>--%>
                                            <%--<c:if test="${page.pageNo+2 lt page.totalPage}">--%>
                                            <%--${page.pageNo+2}--%>
                                            <%--</c:if></a></li>--%>
                                            <li class="paginate_button
                                             <c:if test="${page.last}">
                                                        disabled
                                                    </c:if>
                                             next" id="datatable-keytable_next">
                                                <a href="../Category/page.do?pageNo=${page.getNextNo()}"
                                                   aria-controls="datatable-keytable" data-dt-idx="6"
                                                   tabindex="0">Next</a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->

    <!-- footer content -->
    <%--<footer>--%>
    <%--<div class="pull-right">--%>
    <%--Gentelella - Bootstrap Admin Template by <a href="https://colorlib.com">Colorlib</a>--%>
    <%--</div>--%>
    <%--<div class="clearfix"></div>--%>
    <%--</footer>--%>
    <!-- /footer content -->
</div>


<!-- jQuery -->
<script src="../js/jquery-2.2.4.js"></script>
<!-- Bootstrap -->
<script src="../js/bootstrap.js"></script>
<!-- FastClick -->
<script src="../css/vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="../css/vendors/nprogress/nprogress.js"></script>
<!-- Chart.js -->
<script src="../css/vendors/Chart.js/dist/Chart.min.js"></script>
<!-- gauge.js -->
<script src="../css/vendors/gauge.js/dist/gauge.min.js"></script>
<!-- bootstrap-progressbar -->
<script src="../css/vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
<!-- iCheck -->
<script src="../css/vendors/iCheck/icheck.min.js"></script>
<!-- Skycons -->
<script src="../css/vendors/skycons/skycons.js"></script>
<!-- Flot -->
<script src="../css/vendors/Flot/jquery.flot.js"></script>
<script src="../css/vendors/Flot/jquery.flot.pie.js"></script>
<script src="../css/vendors/Flot/jquery.flot.time.js"></script>
<script src="../css/vendors/Flot/jquery.flot.stack.js"></script>
<script src="../css/vendors/Flot/jquery.flot.resize.js"></script>
<!-- Flot plugins -->
<script src="../css/vendors/flot.orderbars/js/jquery.flot.orderBars.js"></script>
<script src="../css/vendors/flot-spline/js/jquery.flot.spline.min.js"></script>
<script src="../css/vendors/flot.curvedlines/curvedLines.js"></script>
<!-- DateJS -->
<script src="../css/vendors/DateJS/build/date.js"></script>
<!-- Datatables -->
<script src="../css/vendors/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../css/vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
<script src="../css/vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
<script src="../css/vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
<script src="../css/vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
<script src="../css/vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
<script src="../css/vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
<script src="../css/vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
<script src="../css/vendors/datatables.net-scroller/js/dataTables.scroller.min.js"></script>
<script src="../css/vendors/jszip/dist/jszip.min.js"></script>
<script src="../css/vendors/pdfmake/build/pdfmake.min.js"></script>
<script src="../css/vendors/pdfmake/build/vfs_fonts.js"></script>
<!-- JQVMap -->
<script src="../css/vendors/jqvmap/dist/jquery.vmap.js"></script>
<script src="../css/vendors/jqvmap/dist/maps/jquery.vmap.world.js"></script>
<script src="../css/vendors/jqvmap/examples/js/jquery.vmap.sampledata.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="../css/vendors/moment/min/moment.min.js"></script>
<script src="../css/vendors/bootstrap-daterangepicker/daterangepicker.js"></script>

<!-- Custom Theme Scripts -->
<script src="../css/build/js/custom.min.js"></script>


<!-- Mainly scripts -->
<script src="../js/framework/metisMenu/jquery.metisMenu.js"></script>
<script src="../js/framework/slimscroll/jquery.slimscroll.min.js"></script>

<!-- Custom and plugin javascript -->
<script src="../js/framework/inspinia.js"></script>
<script src="../js/framework/pace/pace.min.js"></script>

<!-- Sweet alert -->
<script src="../js/framework/sweetalert/sweetalert.min.js"></script>

<script>
    $(function () {


        $('[data-toggle="tooltip"]').tooltip();
        $('[data-toggle="popover"]').popover();
        $('tbody tr td:nth-child(9) a').mouseenter(function () {
            $('tbody tr td:nth-child(9) img').show();
        }).mouseout(function () {
            $('tbody tr td:nth-child(9) img').hide();
        });



// 查大类型
        $.ajax({
            type: 'post',
            url: '../Category/Categories.do',
            dataType: 'json',
            success: function (res) {
                var littleTypeSelect = $('.big');
                res.forEach(function (type) {

                    var option = new Option(type.bigCtgr, type.id);
                    littleTypeSelect.append(option);


                })
            }
        });


        <%--判断是否修改成功，如果添加成功则弹出模态框--%>
        $('.inserted').click(function () {
            var ctgrId = $('#edit').attr("name");
            var bigCtgr = $('#bigCtgr').val();
            var ctgrName = $('#ctgrName').val();

            $.get("../Category/ModifyCategory.do",
                {"ctgrId": ctgrId, "bigCtgr": bigCtgr, "ctgrName": ctgrName},
                function (res) {
                    if (res.result) {
                        swal({
                                title: "修改结果",
                                text: "成功"
                            },
                            function () {
                                location.reload();
                            });
                    } else {
                        swal({
                            title: "修改结果",
                            text: "失败！",
                            type: "error"
                        });
                    }

                }, "json");


        });


        // 删除
        var ctgrId = $(this).attr('ctgrId');

        $('.delete').click($.ajax({
            type: 'post',
            url: '../Category/Categories.do',
            dataType: 'json',
            data: {"ctgrId": ctgrId},
            success: function (res) {
                if (res.deleted === true) {

                    $('#ctgrId')

                }

            }


        }))


        // 加载完毕执行js结束
    });

    // 查小类型
    function changSCtgr(ele) {
        var bigCtgr = $(ele).val();
        $.ajax({
            type: 'get',
            url: '../Category/queryByBigCtgr.do',
            data: {'bigCtgr': bigCtgr},
            dataType: 'json',
            success: function (res) {
                var littleTypeSelect = $('.small');
                littleTypeSelect.find("option").remove();
                littleTypeSelect.append("<option value=\"\">--请选择--</option>\n");
                res.forEach(function (type) {

                    var option = new Option(type.ctgrName, type.id);
                    littleTypeSelect.append(option);


                })
            }
        })
    }

    // 查小类型
    function deleteById(ele) {
        var bigCtgr = $(ele).val();
        $.ajax({
            type: 'get',
            url: '../Category/queryByBigCtgr.do',
            data: {'bigCtgr': bigCtgr},
            dataType: 'json',
            success: function (res) {
                var littleTypeSelect = $('#small');
                littleTypeSelect.find("option").remove();
                littleTypeSelect.append("<option value=\"\">--请选择--</option>\n");
                res.forEach(function (type) {

                    var option = new Option(type.ctgrName, type.id);
                    littleTypeSelect.append(option);

                })
            }
        })
    }

</script>

</body>
</html>